import 'dart:convert';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yres/tool/constant.dart';
import 'package:dio/dio.dart';
import 'package:flutter_yres/tool/AppSaveInfoUtil.dart';
import 'package:flutter_yres/tool/network/http_url.dart';
import 'package:flutter_yres/tool/network/http_method.dart';
import 'package:flutter_yres/tool/Toast.dart';

class ReferrerPage extends StatefulWidget {
  ReferrerPage({Key key}) : super(key: key);

  @override
  _ReferrerPageState createState() => _ReferrerPageState();
}

class _ReferrerPageState extends State<ReferrerPage> {
  String token = "";

 String uid	= "";//推荐人ID
String group_id= ""	;//推荐人所属会员组
String register_time= "";//	推荐人注册时间
String phone= "";//	推荐人手机号码
String nickname= "";//	推荐人昵称
String avatar= ""	;//推荐人头像

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text(
          "推荐人信息",
          style: TextStyle(
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
              color: Colors.black),
        ),
        elevation: 0.5,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
      ),
      body:  Container(
            height: ScreenUtil.getInstance().setHeight(1334),
            width: ScreenUtil.getInstance().setWidth(750),
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("images/cover.png"),
                fit: BoxFit.cover,
              ),
            ),
            child: Container(
              alignment: Alignment.topLeft,
              margin: EdgeInsets.all(ScreenUtil.getInstance().setWidth(60)),
              child: Column(
                children: <Widget>[
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(30)),
                    child: Text(
                      '欢迎光临',
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w300,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(30)),
                    child: Text(
                      '油然而省',
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w600,
                          fontSize: ScreenUtil.getInstance()
                              .setSp(BIG_FONT_SIZE * 1.5)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(30)),
                    child: Text(
                      '你的推荐人是:' + nickname,
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w500,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setWidth(100)),
                    child: Text(
                      '推荐人手机号:' + phone,
                      style: TextStyle(
                          color: white,
                          fontWeight: FontWeight.w500,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                  ),

                  // Container(child: Text('店铺邀请码'+auth_code==null?'':auth_code),),
                  // Container(child: Text(''),),
                ],
              ),
            )),
    );
  }

 void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
      print(token);
      is_bindTJ();
    });
 }
    is_bindTJ() async {//获取推荐人信息
    Map map = new Map();
    map['token'] = token;
    FormData fromData = FormData.fromMap(new Map<String, dynamic>.from(map));
    Response<String> response =
        await HttpUtil().post(Api.BaseUrl+'/app.php?c=User&a=getRMsg', data: fromData);
    Map userMap = json.decode(response.data);
    int code = userMap["code"];
    String msg = userMap["msg"];
    print(userMap);
    if (code == 1 && mounted) {
      setState(() {
        nickname=userMap['data']['referrerMsg']['nickname'];
        phone=userMap['data']['referrerMsg']['phone'];
      });
     
    } else {
       Toast.toast(context, msg: msg);
    }
  }
}